<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
$setting=uni_setting('cash');
$setting['percent']=round($setting['percent'],2);
if($_RQ['op']=='get'){
	$params=array('merchid'=>$_SESSION['onemerchid'],'mid'=>$_SESSION['uid'],'status'=>1);
	$params['type']=5;
	$return['daili_fee']=$this->sum('commission',$params,'money');
	$return['daili_jifen']=$this->sum('commission',$params,'jifen');
	$params['type']=6;
	$return['ping_fee']=$this->sum('commission',$params,'money');
	$return['ping_jifen']=$this->sum('commission',$params,'jifen');
	if($this->setting['withdrawtype']){
		$withdrawtype=array();
		$check=strstr($this->setting['withdrawtype'],'credit');
		if($check){
			$withdrawtype['credit']=$this->pay_types['credit'];
			$pay_type='credit';
		}
		$check=strstr($this->setting['withdrawtype'],'wechat');
		if($check){
			$withdrawtype['wechat']=$this->pay_types['wechat'];
			$pay_type=$pay_type?:'wechat';
		}
		$check=strstr($this->setting['withdrawtype'],'alipay');
		if($check){
			$withdrawtype['alipay']=$this->pay_types['alipay'];
			$pay_type=$pay_type?:'alipay';
		}
		$check=strstr($this->setting['withdrawtype'],'union');
		if($check){
			$withdrawtype['union']=$this->pay_types['union'];
			$pay_type=$pay_type?:'union';
		}
		$return['pay_types']=$withdrawtype;
	}else{
		$return['pay_types']=$this->pay_types;
		$pay_type='credit';
	}
	$wxapppay_types=array();
	foreach($return['pay_types'] as $k=>$pv){
		$wxapppay_types[]=array(
			'key'=>$k,
			'title'=>$pv,
		);
	}
	$return['wxapppay_types']=$wxapppay_types;
	if($this->setting['daili_jie']){
		$msg1='每人能结算多次，';
	}else{
		$msg1='每人只能结算一次，结算后将不再获得奖金了！';
	}
	if($this->setting['daili_type']==1){
		$msg1 .='奖金满'.$this->setting['daili_manfee'].'元封顶！';
	}
	if($this->setting['ping_jie']){
		$msg2='每人能结算多次，';
	}else{
		$msg2='每人只能结算一次，结算后将不再获得奖金了！';
	}
	if($this->setting['ping_type']==1){
		$msg2 .='奖金满'.$this->setting['ping_manfee'].'元封顶！';
	}
	$tips1='以下完成其中一项即可解冻:';
	if($this->setting['daili_file0']){
			$tips1 .='直推预选团队长'.$this->setting['daili_file0'].'名;';
	}
	if($this->setting['daili_file1']){
			$tips1 .=$this->jichaname.'分红金额满'.$this->setting['daili_file1'].'元;';
	}
	/*if($this->setting['daili_file2']){
			$tips1 .='二级团队长满'.$this->setting['daili_file2'].'名;';
	}
	if($this->setting['daili_file3']){
			$tips1 .='三级团队长满'.$this->setting['daili_file3'].'名;';
	}
	if($this->setting['daili_file4']){
			$tips1 .='四级团队长满'.$this->setting['daili_file4'].'名;';
	}
	*/
	if($this->setting['daili_file5']){
			$tips1 .='商城自购金额满'.$this->setting['daili_file5'].'元;';
	}
	if($this->setting['daili_file6']){
			$tips1 .='直推获得拼团金满'.$this->setting['daili_file6'].'元;';
	}
	if($this->setting['daili_file7']){
			$tips1 .='直推累计购物满'.$this->setting['daili_file7'].'元;';
	}
	$tips2='以下完成其中一项即可解冻:';
	if($this->setting['ping_file0']){
			$tips2 .='直推预选团队长'.$this->setting['ping_file0'].'名;';
	}
	if($this->setting['ping_file1']){
			$tips2 .=$this->jichaname.'分红金额满'.$this->setting['ping_file1'].'元;';
	}
	if($this->setting['ping_file2']){
			$tips2 .='二级团队长满'.$this->setting['ping_file2'].'名;';
	}
	if($this->setting['ping_file3']){
			$tips2 .='三级团队长满'.$this->setting['ping_file3'].'名;';
	}
	if($this->setting['ping_file4']){
			$tips2 .='四级团队长满'.$this->setting['ping_file4'].'名;';
	}
	$return['msg']=$_RQ['type']==5?$msg1:$msg2;
	$return['msg1']=$msg1;
	$return['msg2']=$msg2;
	$return['tips1']=$tips1;
	$return['tips2']=$tips2;
	$return['tips']=$_RQ['type']==5?$tips1:$tips2;
	$return['daili_fee']=$return['daili_fee']?:0.00;
	$return['ping_fee']=$return['ping_fee']?:0.00;
	$return['post']=array(
		'fee'=>$_RQ['type']==5?$return['daili_fee']:$return['ping_fee'],
		'jifen'=>$_RQ['type']==5?$return['daili_jifen']:$return['ping_jifen'],
		'pay_type'=>$pay_type,
		'type'=>intval($_RQ['type'])?:5
	);
	exi($return);
}
//结算
if($_RQ['op']=='balance'){
	$res=$this->model('member')->check_cangetfee('',$post['type']);
	if(!$res){
		exi('您还不能结算该奖金！要满足解冻条件才行！','error');
	}
	$post=get_postdata();
	$this->model('commission')->create_balance($_SESSION['uid'],$post);
	exi('结算成功！','','main');
}